package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhangtai.modules.dto.FundsRecordDto;
import com.zhangtai.modules.dto.SecurityRecordDto;
import com.zhangtai.modules.entity.security.FundsRecordEntity;
import com.zhangtai.modules.entity.security.SecurityBatchGroupEntity;
import com.zhangtai.modules.entity.security.SecurityRecordEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-10-12 10:40:19
 */
@Mapper
public interface SecurityBatchGroupDao extends BaseMapper<SecurityBatchGroupEntity> {


    @Select("<script>select t3.*,t4.name from tb_security_batch t1 left join  tb_security_batch_group t2 on t2.batch_id = t1.id " +
            " left join tb_security_record t3 on t2.record_id = t3.record_id " +
            " left join tb_employee_info t4 on t4.oid = t3.oid " +
            " left join tb_security s on s.security_id = t1.security_id  " +
            "<where> t1.id = #{id} " +
//            "<if test='orgIds!=null and orgIds.size>0'> and t3.unit_id in " +
//            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
//            "</if>"+
//            "<if test='orgIds==null or orgIds.size==0'> and t3.unit_id = null </if>" +
            "<if test='contractIds!=null and contractIds.size>0'> and s.contract_main_id in " +
            " <foreach item=\"contractId\" index=\"index\" collection=\"contractIds\" open=\"(\" separator=\",\" close=\")\">#{contractId}</foreach>" +
            "</if>"+
            "<if test='contractIds==null or contractIds.size==0'> and s.contract_main_id = null </if>" +
            "</where> </script>")
    List<SecurityRecordDto> getSecurityBatchGroupList(@Param("id") String id, @Param("contractIds")List<Long> contractIds);

    @Select("<script>select t3.*,t4.name from tb_security_batch t1 left join  tb_security_batch_group t2 on t2.batch_id = t1.id " +
            "left join tb_funds_record t3 on t2.record_id = t3.record_id " +
            "left join tb_employee_info t4 on t4.oid = t3.oid" +
            " left join tb_security s on s.security_id = t1.security_id  " +
            "<where> t1.id = #{id} "+
//            "<if test='orgIds!=null and orgIds.size>0'> and t3.unit_id in " +
//            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
//            "</if>"+
//            "<if test='orgIds==null or orgIds.size==0'> and t3.unit_id = null </if>" +
            "<if test='contractIds!=null and contractIds.size>0'> and s.contract_main_id in " +
            " <foreach item=\"contractId\" index=\"index\" collection=\"contractIds\" open=\"(\" separator=\",\" close=\")\">#{contractId}</foreach>" +
            "</if>"+
            "<if test='contractIds==null or contractIds.size==0'> and s.contract_main_id = null </if>" +
            "</where> </script>")
    List<FundsRecordDto> getFundsBatchGroupList(@Param("id") String id, @Param("contractIds")List<Long> contractIds);
}
